package com.qf.edu.controller;

import com.qf.edu.entity.PatientSign;
import com.qf.edu.service.PatSignService;
import com.qf.edu.service.impl.PatSignServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author:huayuzhuo
 * @email:2798866329@qq.com
 * @desc:病人体征记录控制
 * @datatime: 2022/5/25 9:38
 */
@WebServlet("/patientSignCom")
public class PatientSignCom extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");

        String idNumber = req.getParameter("idNumber");
        String name = req.getParameter("name");
        String doctorName = req.getParameter("doctorName");
        String temperature = req.getParameter("temperature");
        String heartRate = req.getParameter("heartRate");
        String bloodPressure = req.getParameter("bloodPressure");
        String bloodSugar = req.getParameter("bloodSugar");
        String remarks = req.getParameter("remarks");
        PatientSign patientSign = new PatientSign();
        patientSign.setIdNumber(idNumber);
        patientSign.setName(name);
        patientSign.setDrugName(doctorName);
        patientSign.setHeat(temperature);
        patientSign.setRate(heartRate);
        patientSign.setPressure(bloodPressure);
        patientSign.setGlucose(bloodSugar);
        patientSign.setRemark(remarks);

        PatSignService patSignService = new PatSignServiceImpl();
        int i = patSignService.PatSignSer(patientSign);
        System.out.println("录入病人体征:");
        if (i != 0){
            System.out.println("录入成功");
            resp.getWriter().println("录入成功<br>");
        } else {
            System.out.println("录入失败");
            resp.getWriter().println("录入失败<br>");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
